package com.fjut.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjut.exception.CustomException;
import com.fjut.exception.GlobalException;
import com.fjut.mapper.TeacherMapper;
import com.fjut.model.vod.Teacher;
import com.fjut.service.TeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fjut.vo.vod.TeacherQueryVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import static com.fjut.dateBase.TeacherField.*;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author DengTianxun
 * @since 2023-03-02
 */
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {

    @Autowired
    private TeacherService teacherService;

    @Override
    public Page<Teacher> getTeacherPage(Long current, Long limit, TeacherQueryVo teacherQueryVo) {
        if (teacherQueryVo == null) {
            return null;
        }
        String name = teacherQueryVo.getName();
        Integer level = teacherQueryVo.getLevel();
        String joinDateBegin = teacherQueryVo.getJoinDateBegin();
        String joinDateEnd = teacherQueryVo.getJoinDateEnd();
        QueryWrapper<Teacher> queryWrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(name)) {
            queryWrapper.like(NAME,name);
        }
        if (!StringUtils.isEmpty(level)) {
            queryWrapper.eq(LEVEL,level);
        }
        if (!StringUtils.isEmpty(joinDateBegin)) {
            queryWrapper.ge(CREATE_TIME,joinDateBegin);
        }
        if (!StringUtils.isEmpty(joinDateEnd)) {
            queryWrapper.le(UPDATE_TIME,joinDateEnd);
        }
        Page<Teacher> teachers = new Page<>(current, limit);
        teacherService.page(teachers,queryWrapper);

        return teachers;
    }
}
